package com.hotel.mapper;

import com.hotel.pojo.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper {

    @Select("select * from orderlist")
    @Results(id = "orderResults", value = {
            @Result(property = "userName", column = "user_name"),
            @Result(property = "hotelName", column = "hotel_name"),
            @Result(property = "startTime", column = "start_time"),
            @Result(property = "endTime", column = "end_time"),
            @Result(property = "guestNumber", column = "guest_number"),
            @Result(property = "hasChild", column = "has_child"),
            @Result(property = "roomCount", column = "room_count")
    })
    List<Order> findAllOrder();

    @Select("select * from orderlist where user_name = #{name}")
    @ResultMap(value = "orderResults")
    List<Order> findOrderByName(String name);

    @Insert("insert into orderlist(user_name, hotel_name, type, price, start_time, end_time, guest_number, has_child, room_count) values(#{userName}, #{hotelName}, #{type}, #{price}, #{startTime}, #{endTime}, #{guestNumber}, #{hasChild}, #{roomCount})")
    void addOrder(Order order);

    @Delete("delete from orderlist where user_name = #{name}")
    void deleteOrder(String name);
}
